package lee.vioson.remotedata.bean

import com.google.gson.Gson
import com.google.gson.annotations.Expose
import com.google.gson.reflect.TypeToken

/**
 *Author:viosonlee
 *Date:2023/6/9
 *DESCRIPTION:
 */
data class AppConfig(@Expose val configList: List<Map<String, String>>) {
    companion object {
        const val configCode = "configCode"
        const val configValue = "configValue"
    }

    val rotationChart: List<BannerData>
        get() = with(
            configList.findLast { it[configCode] == "Rotation_chart" }?.get(configValue)
        ) {
            if (this.isNullOrEmpty()) {
                emptyList()
            } else {
                Gson().fromJson(this, object : TypeToken<List<BannerData>>() {}.type)
            }
        }

    val loginLogo: String
        get() = configList.findLast { it[configCode] == "Login_Logo" }?.get(configValue) ?: ""

    val launcherPic: List<BannerData>
        get() = with(
            configList.findLast { it[configCode] == "open_screen_animation" }?.get(configValue)
        ) {
            if (this.isNullOrEmpty()) {
                emptyList()
            } else {
                Gson().fromJson(this, object : TypeToken<List<BannerData>>() {}.type)
            }
        }

}

data class BannerData(
    val show: Int,
    val imageUrl: String,
    val openJump: Int,
    val linkType: String,
    val url: String,
)